{itemplate 'public/header'}
{if $op == 'role'}
<form action="./index.php" class="form-horizontal form-filter">
	{php echo tpl_form_filter_hidden('system/perm/role');}
	<div class="form-group">
		<label class="col-xs-12 col-sm-3 col-md-2 control-label">状态</label>
		<div class="col-sm-4 col-xs-4">
			<div class="btn-group">
				<a href="{php echo iurl('system/perm/role', array('status' => -1))}" class="btn {if $status == -1}btn-primary{else}btn-default{/if}">不限</a>
				<a href="{php echo iurl('system/perm/role', array('status' => 1))}" class="btn {if $status == 1}btn-primary{else}btn-default{/if}">启用</a>
				<a href="{php echo iurl('system/perm/role', array('status' => 0))}" class="btn {if $status == 0}btn-primary{else}btn-default{/if}">禁用</a>
			</div>
		</div>
	</div>
	<div class="form-group">
		<label class="col-xs-12 col-sm-3 col-md-2 control-label">搜索</label>
		<div class="col-sm-4 col-xs-4">
			<input type="text" name="keyword" value="{$keyword}" class="form-control" placeholder="请输入角色名称">
		</div>
	</div>
	<div class="form-group">
		<label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
		<div class="col-sm-4 col-xs-4">
			<input type="submit" value="筛选" class="btn btn-primary">
		</div>
	</div>
</form>

<form action="" class="form-table form" method="post">
	<div class="panel panel-table">
		<div class="panel-heading">
			<a href="{php echo iurl('system/perm/role_post');}" class="btn btn-primary btn-sm">添加新角色</a>
		</div>
		<div class="panel-body table-responsive js-table">
			{if empty($roles)}
				<div class="no-result">还没有相关数据</div>
			{else}
				<table class="table table-hover">
					<thead class="navbar-inner">
					<tr>
						<th width="40">
							<div class="checkbox checkbox-inline">
								<input type="checkbox" name="ids[]" />
								<label></label>
							</div>
						</th>
						<th>角色名称</th>
						<th>操作员数量</th>
						<th>状态</th>
						<th style="width:150px; text-align:right;">操作</th>
					</tr>
					</thead>
					<tbody>
						{loop $roles $role}
							<tr>
								<td>
									<div class="checkbox checkbox-inline">
										<input type="checkbox" name="ids[]" value="{$role['id']}"/>
										<label></label>
									</div>
								</td>
								<td>{$role['rolename']}</td>
								<td>{php echo intval($user_nums[$role['id']]['total'])}</td>
								<td>
									<input type="checkbox" class="js-checkbox" data-href="{php echo iurl('system/perm/role_status', array('id' => $role['id']));}" data-name="status" value="1" {if $role['status'] == 1}checked{/if}>
								</td>
								<td style="text-align:right;">
									<a href="{php echo iurl('system/perm/role_post', array('id' => $role['id']))}" class="btn btn-default btn-sm">编辑</a>
									<a href="{php echo iurl('system/perm/role_del', array('id' => $role['id']))}" class="btn btn-default btn-sm js-remove" data-confirm="删除后将不可恢复，确定删除吗">删除</a>
								</td>
							</tr>
						{/loop}
					</tbody>
				</table>
				<div class="btn-region clearfix">
					<div class="pull-left">
						<a href="{php echo iurl('system/perm/role_del')}" class="btn btn-primary btn-danger js-batch" data-batch="remove" data-confirm="删除后将不可恢复，确定删除吗?">删除</a>
					</div>
					<div class="pull-right">
						{$pager}
					</div>
				</div>
			{/if}
		</div>
	</div>
</form>
{/if}

{if $op == 'role_post'}
<div class="page clearfix">
	<form class="form-horizontal form form-validate" id="form1" action="" method="post" enctype="multipart/form-data">
		<div class="form-group">
			<label class="col-xs-12 col-sm-3 col-md-2 control-label">角色</label>
			<div class="col-sm-9 col-xs-12">
				<input type="text" name="rolename" value="{$role['rolename']}" class="form-control" required="true"/>
			</div>
		</div>
		<div class="form-group">
			<label class="col-xs-12 col-sm-3 col-md-2 control-label">状态</label>
			<div class="col-sm-9 col-xs-12">
				<div class="radio radio-inline">
					<input type="radio" value="1" name="status" id="status-1" {if $role['status'] == 1}checked{/if}>
					<label for="status-1">启用</label>
				</div>
				<div class="radio radio-inline">
					<input type="radio" value="0" name="status" id="status-0" {if $role['status'] == 0}checked{/if}>
					<label for="status-0">禁用</label>
				</div>
				<div class="help-block">如果禁用，则当前角色的操作员全部会禁止使用</div>
			</div>
		</div>
		<div class="form-group">
			<div class="col-sm-9 col-xs-12">
				<input type="hidden" name="token" value="{$_W['token']}">
				<input type="submit" value="提交" class="btn btn-primary">
			</div>
		</div>
	</form>
</div>
{/if}

{if $op == 'user'}
<form action="./index.php" class="form-horizontal form-filter">
	{php echo tpl_form_filter_hidden('system/perm/user');}
	<div class="form-group">
		<label class="col-xs-12 col-sm-3 col-md-2 control-label">状态</label>
		<div class="col-sm-4 col-xs-4">
			<div class="btn-group">
				<a href="{php echo iurl('system/perm/user', array('status' => -1))}" class="btn {if $status == -1}btn-primary{else}btn-default{/if}">不限</a>
				<a href="{php echo iurl('system/perm/user', array('status' => 1))}" class="btn {if $status == 1}btn-primary{else}btn-default{/if}">启用</a>
				<a href="{php echo iurl('system/perm/user', array('status' => 0))}" class="btn {if $status == 0}btn-primary{else}btn-default{/if}">禁用</a>
			</div>
		</div>
	</div>
	<div class="form-group">
		<label class="col-xs-12 col-sm-3 col-md-2 control-label">搜索</label>
		<div class="col-sm-4 col-xs-4">
			<input type="text" name="keyword" value="{$keyword}" class="form-control" placeholder="请输入操作员名称">
		</div>
	</div>
	<div class="form-group">
		<label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
		<div class="col-sm-4 col-xs-4">
			<input type="submit" value="筛选" class="btn btn-primary">
		</div>
	</div>
</form>

<form action="" class="form-table form" method="post">
	<div class="panel panel-table">
		<div class="panel-heading">
			<a href="{php echo iurl('system/perm/user_post');}" class="btn btn-primary btn-sm">添加新的操作员</a>
		</div>
		<div class="panel-body table-responsive js-table">
			{if empty($users)}
				<div class="no-result">还没有相关数据</div>
			{else}
				<table class="table table-hover">
					<thead class="navbar-inner">
					<tr>
						<th width="40">
							<div class="checkbox checkbox-inline">
								<input type="checkbox" name="ids[]" />
								<label></label>
							</div>
						</th>
						<th>登陆ID</th>
						<th>角色</th>
						<th>姓名</th>
						<th>手机号</th>
						<th>状态</th>
						<th style="width:150px; text-align:right;">操作</th>
					</tr>
					</thead>
					<tbody>
						{loop $users $user}
							<tr>
								<td>
									<div class="checkbox checkbox-inline">
										<input type="checkbox" name="uids[]" value="{$user['uid']}"/>
										<label></label>
									</div>
								</td>
								<td>{$user['username']}</td>
								<td>{$roles[$user['roleid']]['rolename']}</td>
								<td>{$user['realname']}</td>
								<td>{$user['mobile']}</td>
								<td>
									<input type="checkbox" class="js-checkbox" data-href="{php echo iurl('system/perm/user_status', array('id' => $user['id']));}" data-name="status" value="1" {if $user['status'] == 1}checked{/if}>
								</td>
								<td style="text-align:right;">
									<a href="{php echo iurl('system/perm/user_post', array('id' => $user['id']))}" class="btn btn-default btn-sm">编辑</a>
									<a href="{php echo iurl('system/perm/user_del', array('uid' => $user['uid']))}" class="btn btn-default btn-sm js-remove" data-confirm="删除后将不可恢复，确定删除吗">删除</a>
								</td>
							</tr>
						{/loop}
					</tbody>
				</table>
				<div class="btn-region clearfix">
					<div class="pull-left">
						<a href="{php echo iurl('system/perm/user_del')}" class="btn btn-primary btn-danger js-batch" data-batch="remove" data-confirm="删除后将不可恢复，确定删除吗?">删除</a>
					</div>
					<div class="pull-right">
						{$pager}
					</div>
				</div>
			{/if}
		</div>
	</div>
</form>
{/if}

{if $op == 'user_post'}
<div class="page clearfix">
	<form class="form-horizontal form form-validate" id="form1" action="" method="post" enctype="multipart/form-data">
		<div class="form-group">
			<label class="col-xs-12 col-sm-3 col-md-2 control-label">操作员用户名</label>
			<div class="col-sm-9 col-xs-12">
				<input type="text" name="username" value="{$user['username']}" {if $id > 0}readonly{/if} class="form-control" required="true"/>
			</div>
		</div>
		<div class="form-group">
			<label class="col-xs-12 col-sm-3 col-md-2 control-label">操作员密码</label>
			<div class="col-sm-9 col-xs-12">
				<input type="password" name="password" value="" class="form-control" {if empty($_GPC['id'])}required="true"{/if}/>
			</div>
		</div>
		<div class="form-group">
			<label class="col-xs-12 col-sm-3 col-md-2 control-label">所属角色</label>
			<div class="col-sm-9 col-xs-12">
				<select name="roleid" class="form-control">
					<option value="0">选择角色</option>
					{loop $roles $role}
						<option value="{$role['id']}" {if $role['id'] == $user['roleid']}selected{/if}>{$role['rolename']}</option>
					{/loop}
				</select>
				<div class="help-block">如果您选择了角色，则此用户本身就继承了此角色的所有权限</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">姓名</label>
					<div class="col-sm-9 col-xs-12">
						<input type="text" class="form-control" name="realname" value="{$user['realname']}">
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">电话</label>
					<div class="col-sm-9 col-xs-12">
						<input type="text" class="form-control" name="mobile" value="{$user['mobile']}">
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">状态</label>
					<div class="col-sm-9 col-xs-12">
						<div class="radio radio-inline">
							<input type="radio" value="1" name="status" id="status-1" {if $user['status'] == 1}checked{/if}>
							<label for="status-1">启用</label>
						</div>
						<div class="radio radio-inline">
							<input type="radio" value="0" name="status" id="status-0" {if $user['status'] == 0}checked{/if}>
							<label for="status-0">禁用</label>
						</div>
						<div class="help-block">用户可以在此角色权限的基础上附加其他权限</div>
					</div>
				</div>
			</div>
		</div>
		<div class="form-group">
			<div class="col-sm-9 col-xs-12">
				<input type="hidden" name="token" value="{$_W['token']}">
				<input type="submit" value="提交" class="btn btn-primary">
			</div>
		</div>
	</form>
</div>
{/if}
{itemplate 'public/footer'}